package logic

import (
	"context"
	"course-admin/userrpc/userrpc"

	"course-admin/api/internal/svc"
	"course-admin/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGoodsAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsAddLogic {
	return &GoodsAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GoodsAddLogic) GoodsAdd(req *types.GoodsAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	add, err := l.svcCtx.UserRpc.GoodsAdd(l.ctx, &userrpc.GoodsAddRequest{
		GoodsName:    req.GoodsName,
		GoodsPrice:   req.GoodsPrice,
		GoodsContent: req.GoodsContent,
		ClassName:    req.ClassName,
		UserId:       req.UserId,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Data:    nil,
			Code:    500,
		}, nil
	}
	return &types.Response{
		Message: "发布成功",
		Data:    add,
		Code:    200,
	}, nil
}
